//
//  WLRouterInternetSetController.m
//  WanLian
//
//  Created by muzhuang on 2018/10/18.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLRouterInternetSetController.h"
#import "WLRouterInternetSubController.h"
#import "JXCategoryView.h"

@interface WLRouterInternetSetController ()<JXCategoryViewDelegate>

@property (nonatomic, copy) NSArray *arrControllers;

@end

@implementation WLRouterInternetSetController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"联网设置";
    
    NSArray *titleNameArr = @[@"PPPoE",@"静态IP",@"动态IP"];
    
    CGFloat height = HEIGHT_SCREEN_WL-WL_NavTopHeight-WLScaleX(40);
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, WLScaleX(40), WIDTH_SCREEN_WL, height)];
//    scrollView.delegate = self;
    scrollView.pagingEnabled = YES;
    scrollView.contentSize = CGSizeMake(WIDTH_SCREEN_WL*(titleNameArr.count), height);
    scrollView.bounces = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    
    JXCategoryTitleView *categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN_WL, WLScaleX(40))];
    categoryView.delegate = self;
    categoryView.titles = titleNameArr;
    categoryView.titleColor = wlLightTextColor;
    categoryView.titleSelectedColor = wlBlackColor;
    categoryView.cellWidth = WLScaleX(75);
    categoryView.titleFont = [WLCommonTool fontTypePingFangSCRegular:16];
    //2、添加并配置指示器
    //lineView
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorLineViewColor = wlblueColor;
    lineView.indicatorLineWidth = WLScaleX(50);//JXCategoryViewAutomaticDimension;
    lineView.lineStyle = JXCategoryIndicatorLineStyle_IQIYI;
    //backgroundView
//    JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
//    backgroundView.backgroundViewColor = [UIColor redColor];
//    backgroundView.backgroundViewWidth = JXCategoryViewAutomaticDimension;
    categoryView.indicators = @[lineView];
    
    //3、绑定contentScrollView。self.scrollView的初始化细节参考源码。
    categoryView.contentScrollView = scrollView;
    [self.view addSubview:categoryView];
    
    WLRouterInternetSubController *pppoeVC = [[WLRouterInternetSubController alloc] init];
    pppoeVC.netType = 0;
//    pppoeVC.netModel = self.netConfig;
    WLRouterInternetSubController *staticVC = [[WLRouterInternetSubController alloc] init];
    staticVC.netType = 1;
//    staticVC.netModel = self.netConfig;
    WLRouterInternetSubController *dynamicVC = [[WLRouterInternetSubController alloc] init];
    dynamicVC.netType = 2;
//    dynamicVC.netModel = self.netConfig;
    NSArray *controllerArray = @[pppoeVC,staticVC,dynamicVC];
    self.arrControllers = controllerArray;
    
    if ([self.netType isEqualToString:@"static"]) {
        categoryView.defaultSelectedIndex = 1;
    }
    else if ([self.netType isEqualToString:@"dhcp"])
    {
        categoryView.defaultSelectedIndex = 2;
    }
    
    for (int i = 0;  i<titleNameArr.count; i++) {
        UIViewController *controller = controllerArray[i];
        [self addChildViewController:controller];
        controller.view.frame = CGRectMake(WIDTH_SCREEN_WL*i, 0, WIDTH_SCREEN_WL, height);
        [scrollView addSubview:controller.view];
    }
    
//    if ([self.netConfig.sord isEqualToString:@"static"]) {
//        categoryView.defaultSelectedIndex = 1;
//    }
//    else if ([self.netConfig.sord isEqualToString:@"dynamic"])
//    {
//        categoryView.defaultSelectedIndex = 2;
//    }
}

//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//
//}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    //侧滑手势处理
//    if (_shouldHandleScreenEdgeGesture) {
//        self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
//    }
//    WLLog(@"____%d",index);
    WLRouterInternetSubController *subContrller = self.arrControllers[index];
    [subContrller receiveRouterConnectGetAgain];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
